#include<arbb.hpp>
// Used by the mark array
#define UNVISITED 0
#define VISITED 1

#include "GRAPH.h"

class Graphm : public Graph { // Implement adjacency matrix
private:
  i32 numVertex, numEdge; // Store number of vertices, edges
  i32 **matrix;           // Pointer to adjacency matrix
  i32 *mark;              // Pointer to mark array
public:
  Graphm(i32 numVert) {   // Make graph w/ numVert vertices
    i32 i;
    numVertex = numVert;
    numEdge = 0;
    mark = new i32[numVert]; // Initialize mark array
    for (i=0; i<numVertex; i++)
      mark[i] = UNVISITED;
    matrix = (i32**) new i32*[numVertex]; // Make matrix
    for (i=0; i<numVertex; i++)
      matrix[i] = new i32[numVertex];
    for (i=0; i< numVertex; i++) // Edges start w/ 0 weight
      for (i32 j=0; j<numVertex; j++) matrix[i][j] = 0;
  }

  ~Graphm() {       // Destructor
    delete [] mark; // Return dynamically allocated memory
    for (i32 i=0; i<numVertex; i++)
      delete [] matrix[i];
    delete [] matrix;
  }

  i32 n() { return numVertex; } // Number of vertices
  i32 e() { return numEdge; }   // Number of edges

  i32 first(i32 v) {            // Return v's first neighbor
    i32 i;
    for (i=0; i<numVertex; i++)
      if (matrix[v][i] != 0) return i;
    return i;       // Return n if none
  }

  i32 next(i32 v1, i32 v2) { // Get v1's neighbor after v2
    i32 i;
    for(i=v2+1; i<numVertex; i++)
      if (matrix[v1][i] != 0) return i;
    return i;
  }

  // Set edge (v1, v2) to wgt
  void setEdge(i32 v1, i32 v2, i32 wgt) {
    //Assert(wgt>0, "Illegal weight value");
    if (matrix[v1][v2] == 0) numEdge++;
    matrix[v1][v2] = wgt;
  }

  void delEdge(i32 v1, i32 v2) { // Delete edge (v1, v2)
    if (matrix[v1][v2] != 0) numEdge--;
    matrix[v1][v2] = 0;
  }

  i32 weight(i32 v1, i32 v2) { return matrix[v1][v2]; }
  i32 getMark(i32 v) { return mark[v]; }
  void setMark(i32 v, i32 val) { mark[v] = val; }
};

